package yiminsu.com.cn.controller;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import yiminsu.com.cn.beans.LeisurehotelUser;
import yiminsu.com.cn.service.HostUserService;
import yiminsu.com.cn.utils.ResultsUtil;

@RestController
public class UserController {

	@Autowired
	private HostUserService hostUserService;
	
	private ResultsUtil resultsUtil;
	
	//生成唯一Id
	String uuId = UUID.randomUUID().toString().replaceAll("-", "");
	
	//测试
	@RequestMapping("/hostuser.do")
	@ResponseBody
	public Object Gethostuser(String userid){
         userid="492c3ba00edd4125bd27ed1b42ec42e0";
		 return hostUserService.Gethostuser(userid);
	}

	
	/**
	 * 新增子账号
	 * @param fid  父账号的userId
	 * @return
	 */
	@RequestMapping("api/v1/addSonData")
	public ResultsUtil addSonData(@RequestParam("fid") String fid,LeisurehotelUser hotelUser) 
	{
		//新增子账号
		hotelUser.setUserIdentity(2);
		int increased=hostUserService.insertUser(hotelUser);
		if(increased==0) 
		{
			resultsUtil.setMsg("添加失败");
			resultsUtil.setType(false);			
		}else 
		{
			String zid = hotelUser.getUserId();
			//新增父账号和子账号（根据fid,zid)		
			hostUserService.insertMerchant(uuId,fid, zid);			
		}		
		return resultsUtil;	   
	}
	
	/**
	 * 修改子账号
	 * @return
	 */
	@RequestMapping("api/v1/updateSonData")
	public ResultsUtil updateSonData(String zid,String userName,String phoneNumber) 
	{		
		//修改子账号信息
		return hostUserService.updateUser(zid,userName,phoneNumber);		
	}
	
	/**
	 * 解除子账号的管理
	 * @return 
	 */
	@RequestMapping("api/v1/deleteSonData")
    public ResultsUtil deleteSonData(String fid,String zid) 
	{	  
	   //解除子账号的管理
	   return hostUserService.deleteMerchant(fid,zid);
    }
	
}
